package com.cn.springcloudwechat.controller.shop;

import com.cn.springcloudwechat.common.utils.ThreadLocalUtil;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

//微信h5支付
@XmlAccessorType(XmlAccessType.FIELD)
// XML文件中的根标识
@XmlRootElement(name = "xml")
// 控制JAXB 绑定类中属性和字段的排序
@XmlType(propOrder = { "appid", "mch_id", "notify_url", "trade_type", "spbill_create_ip", "nonce_str", "sign", "body",
		"out_trade_no", "total_fee","openid","sign_type","attach" })
public class WeiXinPayConfig implements Serializable {
	private static final long serialVersionUID = 1L;
	public static final String pay_url="https://api.mch.weixin.qq.com/pay/unifiedorder";//支付地址
//	7jcpBjPsMNHhySGy9yCr6T9oSVU8E2HU
	public static final String key="ebb5236a3ad0d5ab386bc114b5b77efd";
	private String 	attach; //自定义参数
	private String appid="wxfe0300a14724e3ea";// 公众账号ID
	private String mch_id="1487035202";// 商户号
	private String sign_type="MD5";
	private String notify_url="http://vc.nuodk.cn/web/weixinPayNotify/mobileNotify";// 通知地址
	//    private String notify_url="http://slf.tunnel.qydev.com/weixinPayNotify/mobileNotify";// 通知地址
	private String trade_type = "JSAPI";// 交易类型MWEB h5支付  JSAPI 公众号支付 NATIVE 扫码支付 APP APP支付
	private String spbill_create_ip;// 终端IP
	private String nonce_str;// 随机字符串
	private String sign;// 签名
	private String body;// 商品描述
	private String out_trade_no;// 商户订单号
	private String openid;
	private int total_fee;// 总金额(分)
//	private String scene_info;// 场景信息
	// {"h5_info": {"type":"Wap","wap_url": "https://pay.qq.com","wap_name":
	// "腾讯充值"}}

	public String getAppId() {
		return appid;
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getMch_id() {
		return mch_id;
	}

	public String getNotify_url() {
		return notify_url;
	}

	public WeiXinPayConfig() {

	}

	public WeiXinPayConfig(String body, int total_fee, String openid, String orderId) {
		super();
        this.attach=orderId+",shop";
		this.openid=openid;
		this.nonce_str = getNonce_str();
		this.body = body;
		this.out_trade_no = getOut_trade_no();
		this.total_fee = total_fee;
//		this.scene_info = getScene_info();
	}

	public String getNonce_str() {
		nonce_str = UUID.randomUUID().toString().trim().replaceAll("-", "");
		return nonce_str;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public String getTrade_type() {
		return trade_type;
	}

	public String getOut_trade_no() {
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");// 设置日期格式
		out_trade_no = df.format(new Date());// new Date()为获取当前系统时间
		out_trade_no = out_trade_no + (UUID.randomUUID().toString().trim().replace("-", "").substring(0, 13));
		return out_trade_no;
	}

	public int getTotal_fee() {
		return total_fee;
	}

	public void setTotal_fee(int total_fee) {
		this.total_fee = total_fee;
	}

	public String getSpbill_create_ip() {
		return spbill_create_ip;
	}

	public void setSpbill_create_ip(String spbill_create_ip) {
		this.spbill_create_ip = spbill_create_ip;
	}

//	public String getScene_info() {
//		JSONObject jsonObject = new JSONObject();
//		JSONObject jsonObject1 = new JSONObject();
//		jsonObject1.put("type", "Wap");
//		jsonObject1.put("wap_url", "http://www.sandcubes.com");
//		jsonObject1.put("wap_name", "腾讯充值");
//		jsonObject.put("h5_info", jsonObject1);
//		return jsonObject.toString();
//	}

	@Override
	public String toString() {
		return "notify_url=" + notify_url ;
	}

//	public String getTonken(){
//		ThreadLocal<HttpServletRequest> request = new ThreadLocal<HttpServletRequest>();
//		String token = request.get().getParameter("token");
//		return token;
//	}


	public String getOpenid() {
		return openid;
	}

    public void setOpenid(String openid) {
        this.openid = openid;
    }


	public String getSign_type() {
		return sign_type;
	}

	public void setSign_type(String sign_type) {
		this.sign_type = sign_type;
	}

	public void setNotify_url(String notify_url) {
		this.notify_url = notify_url;
	}


    public String getAttach() {
        return attach;
    }

    public void setAttach(String attach) {
        this.attach = attach;
    }
}
